﻿<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>一串跟随鼠标的div</title>
<style type="text/css">
div{ width:10px; height:10px; background:red; position:absolute; border-radius:5px}
</style>

</head>

<body>
 <script type="text/javascript">
<!--
for(var i=0;i<50;i++){
	document.write("<div></div>");
	}
//-->
</script>

<script type="text/javascript">
<!--
 var ds=document.getElementsByTagName("div");
  window.onmousemove=function(ev){
	  ev = ev||window.event;
   var divs=document.getElementsByTagName("div");
   for(var i=divs.length-1;i>0;i--){
	   divs[i].style.left = divs[i-1].style.left;
	   divs[i].style.top = divs[i-1].style.top;
	 }
	 divs[0].style.left=ev.clientX+"px";
	 divs[0].style.top=ev.clientY+"px";
   }
   window.onclick=jihe;
   var index=ds.length;
   var time;
   function jihe(){
	   ev = window.event;  
	 var divs=document.getElementsByTagName("div");
   divs[index].style.left = divs[index-1].style.left;
  divs[index].style.top = divs[index-1].style.top;
	  divs[0].style.left=ev.clientX+"px";
	 divs[0].style.top=ev.clientY+"px";
	 index--;
	  if(index==0){
		  window.clearInterval(time)} 
	time= window.setInterval("jihe()",50);
	 }
//-->
</script>
</body>
</html>
